<?php

namespace App\Http\Controllers\Client\Member;

use App\Models\Member\Follow;
use App\Models\Member\Friend;
use App\Models\Member\Level;
use App\Models\Member\Member;
use App\Http\Controllers\RootController as Controller;
use App\Models\Member\Sign;
use App\Models\Posts\Posts;
use App\Models\Work;
use App\Services\Com\StatisticsService;
use App\Services\Com\UtilService;
use App\Services\Member\MemberInfoService;
use App\Services\Member\MemberService;
use Illuminate\Support\Facades\Cache;
use OSS\OssClient;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class FindController extends Controller
{
    public function handle(Member $model)
    {
        if($this->user()->state == -500) return $this->failure('当前账号已注销');

        try {
            $member = $model->with('org')->find($this->id('member'))->toArray();
            $year = date('Y-01-01');

            $work = Work::where('member_id', $this->id('member'))->where('year', $year)->first();

            $row = [];
            $row['id'] = $member['id'];
            $row['avatar'] = $member['avatar'];
            $row['mobile'] = $member['mobile'];
            $row['name'] = $member['name'];
            $row['pos'] = $member['pos'];
            $row['status'] = $member['status'];
            $row['org'] = [
                'title' => $member['org']['title'],
            ];

            $row['work'] = [
                'target'=>empty($work) ? 0:$work['target'],
                'finish'=>empty($work) ? 0:$work['finish'],
            ];
        }catch (\Exception $e){
            return $this->failure($e->getMessage());
        }


        return $this->success($row);
    }
}
